using UnityEngine;
using System.Collections;
 
[RequireComponent(typeof(GUIText))]
public class Fps : MonoBehaviour 
{
	private float 	m_fFrame;
	
	public 	float 	m_fFrequency = 0.5f;
	public 	int 	m_nFramesPerSec { get; protected set; }
 

	private void Start() 
	{
		StartCoroutine( FPS() );
	}
 
	private IEnumerator FPS() 
	{
		for(;;)
		{
			// Capture frame-per-second
			int lastFrameCount = Time.frameCount;
			float lastTime = Time.realtimeSinceStartup;
			yield return new WaitForSeconds(m_fFrequency);
			float timeSpan = Time.realtimeSinceStartup - lastTime;
			int frameCount = Time.frameCount - lastFrameCount;
 
			// Display it
			m_nFramesPerSec = Mathf.RoundToInt(frameCount / timeSpan);
			m_fFrame = m_nFramesPerSec;
		}
	}
	
	void OnGUI()
	{
		GUI.TextField( new Rect (10,60,150,85), "fps : " + m_fFrame );
	}
}